package com.xuanwu.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xuanwu.core.CoreParam;
import com.xuanwu.dao.DataDao;
import com.xuanwu.entity.Column;
import com.xuanwu.service.BaseService;
import com.xuanwu.service.DataService;
import com.xuanwu.utils.FileUtil;
import com.xuanwu.utils.JsonUtil;
import com.xuanwu.utils.SqlUtil;

@Service
public class DataServiceImpl extends BaseService implements DataService {

	@Resource
	private DataDao dataDao;
	
	public List<Map<String, String>> queryData(String tableName) {
		int tableId = dataDao.queryObjectId(tableName);
		String allColumn = dataDao.queryColumn(tableId, CoreParam.QUERY_ALL_COL_KEY);
		Column column = new Column();
		column.setAllColumn(allColumn);
		String strConf = tableConfProp.getProperty(tableName);
		Map<String, Object> conf = JsonUtil.getMap(strConf);
		allColumn = SqlUtil.dealColumn(allColumn, conf);
		// String queryColumn = dataDao.queryColumn(tableId, String.valueOf(conf.get(CoreParam.QUERY_FILTER_COL_KEY)));
		List<Map<String, String>> param = SqlUtil.getQueryParam(FileUtil.read(paramPath.concat(tableName).concat(CoreParam.PARAM_FILE_SUFFIX)));
		String sql = SqlUtil.getQuerySql(tableName, allColumn, param);
		return dataDao.queryData(sql, column);
	}

	public int insertData(String tableName, List<Map<String, String>> data) {
		// TODO Auto-generated method stub
		return 0;
	}

}
